package com.sjm.suchbear.minibookmall;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sjm.suchbear.minibookmall.model.UserModel;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Suchbear on 2018/5/12.
 */
public class UserListAdapter extends BaseAdapter {
    private ViewHolder viewHolder;
    private Context context;
    private List<UserModel> users;

    public UserListAdapter(Context context, List<UserModel> users) {
        this.context = context;
        this.users = users;
    }

    @Override
    public int getCount() {
        if (users != null) {
            return users.size();
        } else {
            return 0;
        }
    }

    @Override
    public Object getItem(int i) {
        return users.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_order, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tvOrderid.setText("用户名：  ".concat(users.get(i).getUsername()));
        viewHolder.tvOrderprice.setVisibility(View.GONE);
        return convertView;
    }


    static class ViewHolder {
        @BindView(R.id.tv_orderid)
        TextView tvOrderid;
        @BindView(R.id.tv_orderprice)
        TextView tvOrderprice;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
